{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第四次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer4文件夹下，谢绝交到master下\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在10月30日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名  陆曼\n",
    "+ 学号  0165185"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一\n",
    "一般的歌，分为主歌和副歌部分。副歌有重复，对比两大功能。这就是A－B的基本曲式形式结构。  \n",
    "请找一首你的主打歌，把歌词打印出来，重复的副歌部分，请写一个函数，调用函数打印出来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "中国的说法-幼稚园杀手\n",
      "\n",
      "幼稚园杀手 2011 神经兮兮\n",
      "中国的说法 这是中国的说法\n",
      "我生在中国 感谢我妈生我\n",
      "现在 在这生活 干活 快活 在说在唱\n",
      "在说唱 在测试反响 在想在改\n",
      "我的脉搏在跟民生对白\n",
      "也学过书法会绘画 会用普通话对话\n",
      "现在在自己做的节拍里废话\n",
      "莫名其妙里的奇妙 你理解得到\n",
      "这不是人人都能唱得了 万能的技巧\n",
      "四个音调 肆意对调 实在惟妙惟肖\n",
      "是微妙的玩笑 说唱比唱歌更需要脑细胞\n",
      "仔细听好 谁唱得更好\n",
      "我相信好的作品都会入侵人民的心\n",
      "无论什么形式 反映当前形势 见机行事\n",
      "我虽然没有开着奔驰行驶 但也在为了银子奔驰\n",
      "房子车子衣食孩子生老病死\n",
      "\n",
      "中国的说法 中国有中国的说法\n",
      "80后90后 不同的活法相同的说法\n",
      "说你说我说他说她说天下\n",
      "全天下只有中国有中国的说法\n",
      "\n",
      "中国的说法 中国有中国的说法\n",
      "80后90后 不同的活法相同的说法\n",
      "说你说我说他说她说天下\n",
      "全天下只有中国有中国的说法\n"
     ]
    }
   ],
   "source": [
    "print ('中国的说法-幼稚园杀手')\n",
    "def hook ():\n",
    "    print ('\\n中国的说法 中国有中国的说法\\n80后90后 不同的活法相同的说法\\n说你说我说他说她说天下\\n全天下只有中国有中国的说法')\n",
    "print ('\\n幼稚园杀手 2011 神经兮兮\\n中国的说法 这是中国的说法\\n我生在中国 感谢我妈生我\\n现在 在这生活 干活 快活 在说在唱\\n在说唱 在测试反响 在想在改\\n我的脉搏在跟民生对白\\n也学过书法会绘画 会用普通话对话\\n现在在自己做的节拍里废话\\n莫名其妙里的奇妙 你理解得到\\n这不是人人都能唱得了 万能的技巧\\n四个音调 肆意对调 实在惟妙惟肖\\n是微妙的玩笑 说唱比唱歌更需要脑细胞\\n仔细听好 谁唱得更好\\n我相信好的作品都会入侵人民的心\\n无论什么形式 反映当前形势 见机行事\\n我虽然没有开着奔驰行驶 但也在为了银子奔驰\\n房子车子衣食孩子生老病死')\n",
    "hook ()\n",
    "hook ()    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二\n",
    "请写一个函数，能够计算均值、样本方差和n(自己写公式哦)。\n",
    "每次输入十个以上的数字，能够输出上述三个统计量。\n",
    "至少调用两次。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n=18\n",
      "均值是:91.61111111111111\n",
      "样本方差是:14097.66339869282\n",
      "n=15\n",
      "均值是:23.866666666666667\n",
      "样本方差是:1074.2666666666667\n"
     ]
    }
   ],
   "source": [
    "def cacul(*x):\n",
    "    n=0\n",
    "    sum1=0\n",
    "    for value in x:\n",
    "        n=n+1\n",
    "        sum1=sum1+value\n",
    "    ave=sum1/n\n",
    "    sum2=0\n",
    "    for value in x:\n",
    "        sum2=(value-ave)**2+sum2\n",
    "        s=sum2/(n-1)\n",
    "    print(\"n=%s\" % n)\n",
    "    print(\"均值是:%s\" % ave)\n",
    "    print(\"样本方差是:%s\" % s)\n",
    "cacul(45,458,54,365,45,89,33,21,54,63,59,26,35,57,48,62,51,84)\n",
    "cacul(10,9,8,7,6,5,4,3,2,1,10,55,99,87,52)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三\n",
    "刚才那个函数，默认的是输出均值、样本方差和n，请在后面添加一个关键词参数，让这个函数可以选择输出样本标准差或方差。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n=18\n",
      "均值是:91.61111111111111\n",
      "输入1计算方差，输入2计算标准差1\n",
      "样本方差是:14097.66339869282\n",
      "n=15\n",
      "均值是:23.866666666666667\n",
      "输入1计算方差，输入2计算标准差2\n",
      "样本标准差是:537.1333333333333\n"
     ]
    }
   ],
   "source": [
    "def cacul(*x):\n",
    "    n=0\n",
    "    sum1=0\n",
    "    for value in x:\n",
    "        n=n+1\n",
    "        sum1=sum1+value\n",
    "    ave=sum1/n\n",
    "    sum2=0\n",
    "    print(\"n=%s\" % n)\n",
    "    print(\"均值是:%s\" % ave)\n",
    "    y=int(input(\"输入1计算方差，输入2计算标准差\"))\n",
    "    if y==1:\n",
    "        for value in x:\n",
    "             sum2=(value-ave)**2+sum2\n",
    "        s=sum2/(n-1)\n",
    "        print(\"样本方差是:%s\" % s)\n",
    "    if y==2:\n",
    "        for value in x:\n",
    "            sum2=(value-ave)**2+sum2\n",
    "        s=sum2/(n-1)\n",
    "        s2=s**1/2\n",
    "        print(\"样本标准差是:%s\" % s2)\n",
    "cacul(45,458,54,365,45,89,33,21,54,63,59,26,35,57,48,62,51,84)\n",
    "cacul(10,9,8,7,6,5,4,3,2,1,10,55,99,87,52)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目四\n",
    "刚才那个函数，请再增加三个关键词参数，让这个参数可以选择输出均值的标准误、最大值、最小值或不输出这三个统计量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n=18\n",
      "均值是:91.61111111111111\n",
      "输入1计算方差，输入2计算标准差2\n",
      "样本标准差是:7048.83169934641\n",
      "输入1显示均值的标准误、最大值、最小值2\n",
      "谢谢使用！\n",
      "n=15\n",
      "均值是:23.866666666666667\n",
      "输入1计算方差，输入2计算标准差1\n",
      "样本方差是:1074.2666666666667\n",
      "输入1显示均值的标准误、最大值、最小值1\n",
      "最小值为1\n",
      "最大值为99\n",
      "均值的标准误为935.8056296296297\n"
     ]
    }
   ],
   "source": [
    "def cacul(*x):\n",
    "    n=0\n",
    "    sum1=0\n",
    "    for value in x:\n",
    "        n=n+1\n",
    "        sum1=sum1+value\n",
    "    ave=sum1/n\n",
    "    sum2=0\n",
    "    print(\"n=%s\" % n)\n",
    "    print(\"均值是:%s\" % ave)\n",
    "    y=int(input(\"输入1计算方差，输入2计算标准差\"))\n",
    "    if y==1:\n",
    "        for value in x:\n",
    "             sum2=(value-ave)**2+sum2\n",
    "        s=sum2/(n-1)\n",
    "        print(\"样本方差是:%s\" % s)\n",
    "    if y==2:\n",
    "        for value in x:\n",
    "            sum2=(value-ave)**2+sum2\n",
    "        s=sum2/(n-1)\n",
    "        s2=s**1/2\n",
    "        print(\"样本标准差是:%s\" % s2)\n",
    "    z=int(input(\"输入1显示均值的标准误、最大值、最小值\"))\n",
    "    if z==1:\n",
    "        a=min (x)\n",
    "        print(\"最小值为%s\" %a)\n",
    "        b=max (x)\n",
    "        print(\"最大值为%s\" %b)\n",
    "        sum3=0\n",
    "        for value in x:\n",
    "            sum3=sum3+value**2\n",
    "        c=(sum3/n-ave**2)/(n/(n-1))\n",
    "        print(\"均值的标准误为%s\"%c)\n",
    "    else:\n",
    "        print (\"谢谢使用！\")\n",
    "cacul(45,458,54,365,45,89,33,21,54,63,59,26,35,57,48,62,51,84)\n",
    "cacul(10,9,8,7,6,5,4,3,2,1,10,55,99,87,52)       "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
